<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('基金投资台账') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('投资主体名称')" prop="investName">
        <el-input
          v-model="queryParams.investName"
          :placeholder="$t('投资主体名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('子基金名称')" prop="dealBaseName">
        <el-input
          v-model="queryParams.dealBaseName"
          :placeholder="$t('子基金名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('项目名称')" prop="investGroupCompany">
        <el-input
          v-model="queryParams.investGroupCompany"
          :placeholder="$t('项目名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>

        <el-button
          v-hasPermi="['deal:contractcontrolpanel:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>

      </el-form-item>
    </el-form>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="ViewInvestAccountVoList" border>
      <el-table-column fixed="left" :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column fixed="left" :label="$t('投资主体名称')" align="center" prop="investName" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <router-link
            v-if="scope.row.investType === 'fund'"
            target="_blank"
            :to="{path:'/fund/fundBasehome',query:{id:scope.row.investInvestId,gpId:scope.row.investInvestId}}"
            class="link_a"
          >{{ scope.row.investName }}</router-link>
          <router-link
            v-else-if="scope.row.investType === 'manager'"
            target="_blank"
            :to="{path:'/fund/gpBase/gpBaseHome',query:{id:scope.row.investInvestId,gpId:scope.row.investInvestId}}"
            class="link_a"
          >{{ scope.row.investName }}</router-link>
          <router-link
            v-else
            target="_blank"
            :to="{path:'/hhqy/base/hhqyBaseHome',query:{id:scope.row.investInvestId,gpId:scope.row.investInvestId}}"
            class="link_a"
          >{{ scope.row.investName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column fixed="left" :label="$t('子基金名称')" align="center" prop="dealBaseName" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,dealType:scope.row.dealType,gpId:scope.row.gpId,dealStatus:scope.row.dealStatus,companyId:scope.row.companyDealId}}"
            class="link_a"
          >{{ scope.row.dealBaseName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column fixed="left" :label="$t('项目名称')" align="center" prop="investGroupCompany" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/company/base/companyBaseHome',query:{companyId:scope.row.companyId, dealId:scope.row.dealId, source:'BF_PORTFOLIO'}}"
            class="link_a"
          >{{ scope.row.investGroupCompany }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('划款金额')+ $t('金额单位')" align="center" prop="total" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.total, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('持股比例(%)')" align="center" prop="sdr" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.sdr, '') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资时间')" align="center" prop="investTime" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.investTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('已回收金额')+ $t('金额单位')" align="center" prop="amountRecovered" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.amountRecovered, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('已退出成本')+ $t('金额单位')" align="center" prop="exitCost" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.exitCost, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('已实现收益')+ $t('金额单位')" align="center" prop="realizedRevenue" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.realizedRevenue, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('未实现收益/损失')+ $t('金额单位')" align="center" prop="loss" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.loss, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('最新估值')+ $t('金额单位')" align="center" prop="latestValuation" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.latestValuation, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('存续期')" align="center" prop="renewalPeriod" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.renewalPeriod) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listViewInvestAccount } from '@/api/bf/view/viewInvestAccount'
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      ViewInvestAccountVoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        dealBaseName: undefined,
        investName: undefined,
        investGroupCompany: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询储备项目列表 */
    getList() {
      this.loading = true
      listViewInvestAccount(this.queryParams).then(response => {
        this.ViewInvestAccountVoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealBaseName: undefined,
        investInvestId: undefined,
        investName: undefined,
        investGroupCompany: undefined,
        dealStatus: undefined,
        gpId: undefined,
        dealType: undefined,
        companyId: undefined,
        sdr: undefined,
        amountRecovered: undefined,
        exitCost: undefined,
        costNotWithdrawn: undefined,
        loss: undefined,
        latestValuation: undefined,
        total: undefined,
        renewalPeriod: undefined,
        realizedRevenue: undefined,
        investTime: undefined,
        investType: undefined,
        dealId: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
     exportHandle() {
      this.$confirm('确定导出Excel吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.downLoadExcel('/bf/view/exportFundBilling', this.queryParams)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消导出'
          })
        })
    }
  }
}
</script>
